<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/30
 * Time: 17:29
 */

namespace App\Model\Backstage;

use App\Model\Base;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class CustomerFollowSourde extends Base
{
    public $table;
    public function __construct()
    {
        parent::__construct();
//        $this->customerfollowsourde = 'customer_follow_sourde'.$this->branch_id;
        $this->table = 'customer_follow_source';
    }

    /**
     * @param $cfs_type_id   房源、客源ID
     * @param $cfs_type  类型（1房源提醒  客源提醒）
     * @param $cfs_user_id  被提醒人的ID 数组
     * @param $cfs_remind_time   提醒时间
     * @param $cfs_content   提醒内容
     * @return mixed
     */
    public function addCustomerFollowSourde($cfs_type_id,$cfid, $cfs_type, $cfs_user_id, $cfs_remind_time, $cfs_content)
    {
        $array = array();
        foreach($cfs_user_id as $k=>$v) {
            if ($v != ''){
                $array1 = ['cfs_type_id' => $cfs_type_id,'cf_id'=>$cfid, 'cfs_type' => $cfs_type, 'cfs_user_id' => $v, 'cfs_remind_time' => $cfs_remind_time, 'cfs_content' => $cfs_content];
                array_push($array, $array1);
            }
        }
        return DB::table($this->table)->insert($array);
    }

    /**
     *
     *用户登陆完进入系统时获取用户当天提醒
     */
    public function getUserFollow(){
        $map[] = ['cfs_user_id', $this->uid];
        $map[] = ['cfs_remind_time', '<=', time()];
        return DB::table($this->table)->where($map)->get();
    }
}